//
//  vector.m
//  Void Dead
//
//  Created by Sidney Just on 02.07.09.
//  Copyright 2009 by Sidney Just
//  This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; 
//  either version 3 of the License, or (at your option) any later version.
//  
//  This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 
//  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
//  

#import "vector.h"


@implementation VD_Vector
@synthesize x, y, z;

#pragma mark -
#pragma mark init dealloc

- (id)init {
	if(self = [super init])
	{
		x = 0;
		y = 0;
		z = 0;
	}
	
	return self;
}

- (void)dealloc {
	[super dealloc];
}

#pragma mark -
#pragma mark Vector calculation

- (void)vec_set:(VD_Vector *)vec {
	x = vec.x;
	y = vec.y;
	z = vec.z;
}

- (void)vec_fill:(float)var {
	x = var;
	y = var;
	z = var;
}

- (void)vec_add:(VD_Vector *)vec {
	x += vec.x;
	y += vec.y;
	z += vec.z;
}

- (void)vec_sub:(VD_Vector *)vec {
	x -= vec.x;
	y -= vec.y;
	z -= vec.z;
}

- (float)vec_dist:(VD_Vector *)vec {
	VD_Vector *temp = [[VD_Vector alloc] init];
	
	temp.x = x - vec.x;
	temp.y = y - vec.y;
	temp.z = z - vec.z;
	
	float distanz = sqrt(temp.x*temp.x + temp.y*temp.y + temp.z*temp.z);   
	[temp release];
	return distanz;
}

- (void)vec_inverse {
	x = -x;
	y = -y;
	z = -z;
}

- (float)vec_length {
	VD_Vector *tempV = [[VD_Vector alloc] init];
	
	float tempF = [self vec_dist:tempV];
	[tempV release];
	return tempF;
}

- (void)vec_scale:(float)factor {
	x *= factor;
	y *= factor;
	z *= factor;
}

@end
